package cn.daniellee.plugin.map;

import java.awt.image.BufferedImage;
import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;

public class QrcodeRenderer extends MapRenderer {
	private BufferedImage[] image;
	private int frameCount = 0;
	private int cTicks = 550;
	private int ticks = 0;
	public static int TICK_FOR_STILLS = 500;

	public QrcodeRenderer(BufferedImage[] bi, int ticks) {
		super(true);
		this.image = bi;
		this.ticks = ticks;
	}

	public QrcodeRenderer(BufferedImage bi, int ticks) {
		super(true);
		this.image = new BufferedImage[1];
		this.image[0] = bi;
		this.ticks = ticks;
	}

	public void render(MapView view, MapCanvas canvas, Player player) {
		if (this.cTicks >= this.ticks) {
			if ((this.image != null) && (this.image[this.frameCount] != null)) {
				canvas.drawImage(0, 0, this.image[this.frameCount]);
			}
			this.frameCount += 1;
			if (this.frameCount >= this.image.length) {
				this.frameCount = 0;
			}
			this.cTicks = 0;
		}
		this.cTicks += 1;
	}
}
